package com.asia5b.a5mall.middleware.logic.viewmodel.order

import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.member.AddressModel
import com.asia5b.a5mall.middleware.model.bean.PostOrderParcelBean
import com.asia5b.a5mall.middleware.model.bean.PostParcelBean
import com.asia5b.a5mall.middleware.model.cart.TransModel
import io.reactivex.functions.Consumer

/**
 * Created by zhangyuncai on 2020/3/10.
 */
class OrderParcelActivityVM :SimpleViewModel() {

    fun getPackList(parcelBeanList: ArrayList<PostParcelBean>) {
        val addressList = arrayListOf<AddressModel>()
        val observable = memberApi.getAddressList()
                .flatMap {
                    addressList.clear()
                    addressList.addAll(it)
                    tradeApi.getPackList(parcelBeanList)
                }
        baseSubscribe(observable, Consumer {
            if (it.isSuccess) {
//                providerView().getPackListResult(it.data,addressList)
                getPackListResultLiveData.value=arrayOf(it.data,addressList)
            }
        })
    }
    val getPackListResultLiveData= MutableLiveData<Array<*>>()
    val getInterTranserResultLiveData= MutableLiveData<ArrayList<TransModel>>()
    val orderParcelResultLiveData= MutableLiveData<Boolean>()
    fun getInterTranser(adder_id: Int,
                        house_id: Int,
                        traits: Int) {
        baseSubscribe(tradeApi.getInterTranser(adder_id, house_id,traits), Consumer {
            if (it.isSuccess) {
//                providerView().getInterTranserResult(it.data)
                getInterTranserResultLiveData.value=it.data
            }
        })
    }

    /**
     * 申请打包
     */
    fun orderParcel(postOrderParcelBean: PostOrderParcelBean) {
        baseSubscribe(tradeApi.orderParcel2(postOrderParcelBean.getMap()), Consumer {
            if (it.isSuccess) {
//                providerView().orderParcelResult()
                orderParcelResultLiveData.value=true
            }
        })
    }
}